package ThreadDemo.ThreadDemo5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-07-21
 * Time：22:19
 */


public class ThreadDemo2 {
    public  static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1= new Thread(()-> {
            System.out.println(count++);
        });

        Thread t2= new Thread(()-> {
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);

        });
        Thread t3= new Thread(()-> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t4= new Thread(()-> {
            try {
                t3.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t5= new Thread(()-> {
            try {
                t4.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t6= new Thread(()-> {
            try {
                t5.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t7= new Thread(()-> {
            try {
                t6.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t8= new Thread(()-> {
            try {
                t7.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t9= new Thread(()-> {
            try {
                t8.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });
        Thread t10= new Thread(()-> {
            try {
                t9.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(count++);
        });




        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
        t7.start();
        t8.start();
        t9.start();
        t10.start();


        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        t6.join();
        t7.join();
        t8.join();
        t9.join();
        t10.join();


        System.out.println("ok");
    }



}
